<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/11/25
 * Time: 20:19
 */

namespace Community\Model;


use Think\Model;

class ClientBookModel extends Model
{
    /**
     * 用户根据状态码 查询订单列表 包括被服务人信息
     * @param $user_id  用户id
     * @param $status   订单状态码
     * @param $p        分页
     * @return mixed
     */
    public function getOrderList($user_id,$status,$p){
        return $this->field('hd_client_book.id,ordid,price,amount,name,city,fake_id,detail_adress,starttime,servertime')->join("left join __BE_SERVEPEOPLE__ bs on __CLIENT_BOOK__.beserve_id=bs.id")->where(['hd_client_book.user_id'=>$user_id,'ordstatus'=>$status])->page($p,'5')->order('id desc')->select();
    }

    /**
     * 根据id获取订单详情 包括订单对应的被服务人的信息
     * @param $id
     * @return mixed
     */
    public function getOrderDetail($id){
        return $this->field('hd_client_book.id,ordid,hd_client_book.price,amount,bs.name,city,fake_id,detail_adress,age,sex,height,weight,self_live,linkman,linkphone,yesorno_eat,server_type,servertime,starttime,instruction,ordstatus,p.name as package_name,unit')->join("left join __BE_SERVEPEOPLE__ bs on __CLIENT_BOOK__.beserve_id=bs.id")->join("left join __PACKAGE__ p on __CLIENT_BOOK__.package_id=p.id")->where(['hd_client_book.id'=>$id])->find();
    }

    /**
     * 根据id删除订单
     * @param $id
     * @return mixed
     */
    public function removeOrder($id){
        return $this->where(['id'=>$id])->delete();
    }
}